package it.tukano.collections;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * ArrayList extension
 * @author pgi
 * @param <T> 
 */
public class ArrayListExt<T> extends ListExt<T> {

    /* Serial version of this class */
    private static final long serialVersionUID = 0;

    /**
     * Instance initializer
     */
    public ArrayListExt() {
        super(new ArrayList<T>());
    }

    /**
     * Initializes this array list with an initial empty space
     * @param size the initial empty space (in entry-count)
     */
    public ArrayListExt(int size) {
        super(new ArrayList<T>(size));
    }

    /**
     * Initializes this array list with the elements of the given array
     * @param elements the array to use to initialize this list. Can be null. If
     * null, the array list will be empty
     */
    public ArrayListExt(T[] elements) {
        super(generateArrayList(elements));
    }
    
    private static <T> ArrayList<T> generateArrayList(T[] elements) {
        if(elements == null) return new ArrayList<T>();
        return new ArrayList<T>(Arrays.asList(elements));
    }
}
